package com.gobang.demo.controller;

import com.gobang.demo.model.LoginRequest;
import com.gobang.demo.model.LoginResponse;

import com.gobang.demo.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public LoginResponse login(@RequestBody LoginRequest loginRequest,HttpServletRequest request) {
        log.info("用户登录, userName:{}", loginRequest.getUserName());
        return userService.login(loginRequest.getUserName(),loginRequest.getPassword(),request);
    }

    @RequestMapping("/getUserInfo")
    public LoginResponse getUserInfo(HttpServletRequest request) {
        log.info("获取用户信息");
        return userService.getUserInfo(request);
    }

    @RequestMapping("/register")
    public Integer register(String userName, String password) {
        log.info("用户注册, userName:{}", userName);
        return userService.register(userName,password);
    }
}
